package client.StackTest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.UnknownHostException;

import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

public class StackTest01 {

	public static void main(String[] args) throws UnknownHostException, IOException {
		SSLSocket s = (SSLSocket) SSLSocketFactory.getDefault().createSocket("localhost", 9988);
		s.setEnabledCipherSuites(s.getSupportedCipherSuites());
		PrintWriter writer = new PrintWriter(s.getOutputStream());
		BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
		
		System.out.println("trying auth");
		writer.println("user");
		writer.println("passwd");
		writer.flush();
		
		System.out.println("trying IntegerStackMachine");
		writer.println("IntStackMachine");
		writer.flush();
		
		System.out.println("sending numbers: 1 2 3, followed by 2 times add, followed by pop");
		writer.println("1");
		writer.println("2");
		writer.println("3");
		writer.println("add");
		writer.println("add");
		writer.println("pop");
		writer.flush();
		
		System.out.println("trying to read response");
		System.out.println(reader.readLine());
		
		System.out.println("exiting StackMachine");
		writer.println("exit");
		writer.flush();
		
		System.out.println("exiting connection");
		writer.println("exit");
		writer.flush();
		
		System.out.println("trying to read response");
		System.out.println(reader.readLine());
		
		System.out.println("closing connection");
		reader.close();
		writer.close();
		s.close();
	}

}
